#!/usr/bin/python3
# -*- encoding=utf-8 -*-

import requests
#登录函数
class User:
    def __init__(self,headers,session):  #构造函数
        self.headers = headers
        self.session = session
    def do_login( self,userName,password ):
        #session = requests.session()
        #headers = {'Gridview-Token': 'OzSBLmLbGPXR0kWccMmFLA==',}
        
        url = 'http://172.99.1.102:6080/user/login.action?userName=%s&password=%s'%(userName,password)
        req = self.session.get(url,headers=self.headers)
        rtext = req.text
        print(rtext)
        status = req.status_code
        print(status)
        return  rtext 

    def login( self,userName,password ):
        f = 1
        flag = '"success":true'
        
        for i in  range(5):
            rtext = self.do_login(userName,password )
            if userName in rtext and flag in rtext :                   
                print('登录成功')
                f = 0
                break     
            else:
                print('登录失败,重试')

        if f == 1:
            print('登录失败')
            return 1
        else:
            return rtext  




